﻿using System.Security.Principal;
using System.Web.Mvc;
using CodeStash.Controllers;

namespace CodeStash.Filters
{
    public class RenderTagCloudAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            IPrincipal user = ((Controller)filterContext.Controller).User;
      
            //if (user != null && user.Identity.IsAuthenticated)
            {
                if (filterContext.Controller is BaseTagCloudEnabledController)
                {
                    ((BaseTagCloudEnabledController)filterContext.Controller).RenderAndCalculateTagCloud();
                }

                if (filterContext.Controller is BaseTagCloudEnabledAsyncController)
                {
                    ((BaseTagCloudEnabledAsyncController)filterContext.Controller).RenderAndCalculateTagCloud();
                }
            }
        }
    }
}